﻿@model RightControl.Model.ShipTemplate
@using RightControl.Model;
@{
    ViewBag.Title = "运费模板";
    Layout = "~/Areas/Admin/Views/Shared/_LayoutForm.cshtml";
}

<style type="text/css">
    .layui-form-label {
        width: 100px;
    }

    .layui-input-block {
        margin-left: 130px;
    }

    .layui-textarea {
        min-height: 90px;
    }

    .selectItem-width {
        width: 120px;
    }
</style>
<form id="form" class="layui-form" action="/DataSrv/Ship/DhAdd" method="post">
    <div class="layui-fluid">
        <div class="layui-row layui-col-space15">
            <div class="layui-col-md12">
                <div class="layui-card">
                    <div class="layui-card-header">模板信息</div>
                    <div class="layui-card-body" pad15>
                        <div class="layui-form-item">
                            <div class="layui-inline">
                                <label class="layui-form-label"><span class="fRed">*</span>模板名称:</label>
                                <div class="layui-input-inline">
                                    <input name="TemplateName" id="Icon" lay-verify="required" lay-vertype="tips" class="layui-input" type="text" />
                                </div>
                            </div>
                        </div>
                        <div class="layui-form-item">
                            <div class="layui-inline">
                                <label class="layui-form-label"><span class="fRed">*</span>授权店铺:</label>
                                <div class="layui-input-inline">
                                    <select lay-verify="required" lay-search="" id="selAuthShop" name="AuthId" lay-filter="authShop"></select>
                                </div>
                            </div>

                            <div class="layui-inline">
                                <label class="layui-form-label">类目:</label>
                                <div class="layui-input-inline">
                                    <select lay-verify="required" lay-search="" id="selCategory" name="DhCatePubId" lay-filter="category">
                                        <option value="" selected="selected">请选择</option>
                                    </select>
                                </div>
                            </div>
                        </div>
                        <div class="layui-form-item">
                            <div class="layui-inline">
                                <label class="layui-form-label">品牌:</label>
                                <div class="layui-input-inline">
                                    <select lay-verify="required" lay-search="" id="selBrand" name="Brand">
                                        <option value="" selected="selected">请选择</option>
                                    </select>
                                </div>
                            </div>

                            <div class="layui-inline">
                                <label class="layui-form-label">尺码模板:</label>
                                <div class="layui-input-inline">
                                    <select lay-verify="required" lay-search="" id="sizeTemplate" name="SizeTemplate"></select>
                                </div>
                            </div>
                        </div>

                        <div class="layui-form-item">
                            <div class="layui-inline">
                                <label class="layui-form-label"><span class="fRed">*</span>运费模板:</label>
                                <div class="layui-input-inline">
                                    <select lay-verify="required" lay-search="" id="selShip" name="DhShipTemplate"></select>
                                </div>
                            </div>

                            <div class="layui-inline">
                                <label class="layui-form-label"><span class="fRed">*</span>售后模板:</label>
                                <div class="layui-input-inline">
                                    <select lay-verify="required" lay-search="" id="selAfterSale" name="AfterSaleTemplate"></select>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>

                <div class="layui-card">
                    <div class="layui-card-header">价格利润</div>
                    <div class="layui-card-body" pad15>
                        <div class="layui-form-item">
                            <div class="layui-inline">
                                <label class="layui-form-label"><span class="fRed">*</span>国内头程:</label>
                                <div class="layui-input-inline" style="width: 50%">
                                    <select id="selToucheng" name="DomesticHL">
                                        <option value="" selected="selected">请选择</option>
                                        <option value="0"> 0 </option>
                                        <option value="1"> 1 </option>
                                        <option value="2"> 2 </option>
                                        <option value="3"> 3 </option>
                                        <option value="4"> 4 </option>
                                        <option value="5"> 5 </option>
                                        <option value="6"> 6 </option>
                                        <option value="7"> 7 </option>
                                        <option value="8"> 8 </option>
                                        <option value="9"> 9 </option>
                                        <option value="10"> 10 </option>
                                        <option value="11"> 11 </option>
                                        <option value="12"> 12 </option>
                                        <option value="13"> 13 </option>
                                        <option value="14"> 14 </option>
                                        <option value="15"> 15 </option>
                                        <option value="16"> 16 </option>
                                        <option value="17"> 17 </option>
                                        <option value="18"> 18 </option>
                                        <option value="19"> 19 </option>
                                        <option value="20"> 20 </option>
                                    </select>
                                </div>
                            </div>

                            <div class="layui-inline">
                                <label class="layui-form-label"><span class="fRed">*</span>利润率:</label>
                                <div class="layui-input-inline" style="width: 50%">
                                    <select id="selProfit" name="ProfitRate">
                                        <option value="" selected="selected">请选择</option>
                                        <option value="0.2"> 20% </option>
                                        <option value="0.3"> 30% </option>
                                        <option value="0.4"> 40% </option>
                                        <option value="0.5"> 50% </option>
                                        <option value="0.6"> 60% </option>
                                        <option value="0.7"> 70% </option>
                                        <option value="0.5"> 80% </option>
                                        <option value="0.9"> 90%</option>
                                        <option value="1"> 100% </option>
                                        <option value="1.2"> 120% </option>
                                        <option value="1.5"> 150% </option>
                                        <option value="1.8"> 180% </option>
                                        <option value="2"> 200% </option>
                                        <option value="2.5"> 250% </option>
                                        <option value="3"> 300% </option>
                                    </select>
                                </div>
                            </div>
                        </div>

                        <div class="layui-form-item">
                            <div class="layui-inline">
                                <label class="layui-form-label" title="订单金额达到300"><span class="fRed">*</span>一档折扣:</label>
                                <div class="layui-input-inline" style="width: 50%">
                                    <select id="selFstDiscount" name="FstDiscount">
                                        <option value="" selected="selected">请选择</option>
                                        <option value="0.1"> 10% </option>
                                        <option value="0.11"> 11% </option>
                                        <option value="0.12"> 12% </option>
                                        <option value="0.13"> 13% </option>
                                        <option value="0.14"> 14% </option>
                                        <option value="0.15"> 15% </option>
                                        <option value="0.16"> 16% </option>
                                        <option value="0.17"> 17% </option>
                                        <option value="0.18"> 18% </option>
                                    </select>
                                </div>
                            </div>

                            <div class="layui-inline">
                                <label class="layui-form-label" title="订单金额达到1000"><span class="fRed">*</span>二档折扣:</label>
                                <div class="layui-input-inline" style="width: 50%">
                                    <select id="selSecDiscount" name="SecDiscount">
                                        <option value="" selected="selected">请选择</option>
                                        <option value="0.11"> 11% </option>
                                        <option value="0.12"> 12% </option>
                                        <option value="0.13"> 13% </option>
                                        <option value="0.14"> 14% </option>
                                        <option value="0.15"> 15% </option>
                                        <option value="0.16"> 16% </option>
                                        <option value="0.17"> 17% </option>
                                        <option value="0.18"> 18% </option>
                                        <option value="0.19"> 19% </option>
                                    </select>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>

                <div class="layui-card">
                    <div class="layui-form-item">
                        <div class="layui-input-block">
                            <button class="layui-btn" lay-submit="" lay-filter="submitForm" id="submitForm">确认保存</button>
                            <div class="div-msg fl" style="float:left;">@ViewBag.Msg</div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</form>

<script type="text/javascript">
    layui.use(['form','laydate'], function () {
        var laydate = layui.laydate;
        var form = layui.form,
            $ = layui.$;         
        //日期范围
        laydate.render({
            elem: '#promoteDate'
          , range: true
        });

        init();

        form.on('select(authShop)', function (data) {
            //location.href = '/datasrv/product?id=12&category=' + data.value;
            initSelOptions(data.value)
        });
      

        form.on('select(category)', function (data) {
            layer.load(); //loading
            $.ajax({
                url: "/Datasrv/Ship/GetSizeTemplates?catePubId=" + data.value,
                dataType: "json",
                success: function (result) {
                    if (result != null && result.length > 0) {
                        for (var i = 0; i < result.length; i++) {
                            $("#sizeTemplate").append("<option value='" + result[i].sizeTemplateId + "'>" + result[i].templateNameCn + "</option>");
                        }
                        form.render('select');                     
                    }
                    layer.closeAll('loading'); //关闭loading
                }
            })
        });
     
        submitForm(form, "更新成功"); //监听提交

        function init() {
            $.ajax({
                url: "/AuthPlatForm/List?PlatForm=3&page=1&limit=100",
                dataType: "json",
                success: function (result) {
                    if (result != null) {
                        if (result.data != null) {
                            var selVal = '',defaultVal = '';
                            for (var i = 0; i < result.data.length; i++) {
                                if (i == 0) {
                                    selVal = "selected";
                                    defaultVal = result.data[i].Id;
                                } else {
                                    selVal = "";
                                }
                                $("#selAuthShop").append("<option value='" + result.data[i].Id + "'" + selVal + ">" + result.data[i].ShopName + "</option>");
                            }

                            initSelOptions(defaultVal);                      
                        }
                    }
                }
            });
        }

        function initSelOptions(authId) {
            layer.load(); //loading
            $.ajax({
                url: "/Datasrv/Ship/GetDhUserTemplates?authId=" + authId,
                dataType: "json",
                success: function (result) {                   
                    if (result != null) {
                        if (result.BrandList != null) {
                            for (var i = 0; i < result.BrandList.length; i++) {
                                $("#selBrand").append("<option value='" + result.BrandList[i].brandId + "'>" + result.BrandList[i].brandNameCn + "</option>");
                            }
                        }

                        if (result.ShipTemplate != null) {
                            for (var i = 0; i < result.ShipTemplate.length; i++) {
                                $("#selShip").append("<option value='" + result.ShipTemplate[i].shippingTempId + "'>" + result.ShipTemplate[i].modelName + "</option>");
                            }
                        }

                        if (result.AfterSaleTemplate != null) {
                            for (var i = 0; i < result.AfterSaleTemplate.length; i++) {
                                $("#selAfterSale").append("<option value='" + result.AfterSaleTemplate[i].afterSaleTemplateId + "'>" + result.AfterSaleTemplate[i].name + "</option>");
                            }
                        }
                        if (result.CategoryList != null) {
                            for (var i = 0; i < result.CategoryList.length; i++) {
                                $("#selCategory").append("<option value='" + result.CategoryList[i].DhCatePubId + "'>" + result.CategoryList[i].Description + "</option>");
                            }
                        }

                        //if (result.SizeTemplate != null) {
                        //    for (var i = 0; i < result.SizeTemplate.length; i++) {
                        //        $("#sizeTemplate").append("<option value='" + result.SizeTemplate[i].sizeTemplateId + "'>" + result.SizeTemplate[i].templateNameCn + "</option>");
                        //    }
                        //}

                        form.render();
                        layer.closeAll('loading'); //关闭loading
                    }
                }
            });
        }
    });


    //$("#promoteDate").value

</script>